﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WF.Model;
using WF.DAL;

namespace WF.BusinessObject
{
    /// <summary>
    /// SystemSetting业务对象
    /// </summary>
    public class SystemSetting : BOBase<SystemSettingEntity, DAL.SystemSetting>
    {
        #region 构造函数

        public SystemSetting() : base() { }
        public SystemSetting(WFDBDataContext DataContext) : base(DataContext) { }
        #endregion

        #region 实现基类abstract方法
        /// <summary>
        /// 实现基类的GetById abstract方法
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override SystemSettingEntity GetById(string ID)
        {
            var obj = DataContext.SystemSettings.SingleOrDefault(o => o.RowID == ID);
            return new SystemSettingEntity(obj);
        }
        #endregion

        #region Public 方法
        public List<SystemSettingEntity> GetAll()
        {
            var target = DataContext.SystemSettings.ToList();
            List<SystemSettingEntity> _result = new List<SystemSettingEntity>();
            foreach (var item in target)
            {
                _result.Add(new SystemSettingEntity(item));
            }
            return _result;
        }

        public string GetValueByParamName(string paramName)
        {
            DAL.SystemSetting setting = DataContext.SystemSettings.SingleOrDefault(obj => obj.ParamName == paramName);
            if (setting != null)
                return setting.ParamValue;
            else
                return "";
        }

        #endregion

        #region SystemSetting
        /// <summary>
        /// 获取所有系统设置

        /// </summary>
        /// <param name="systemSettingEntityList"></param>
        /// <returns></returns>
        public bool GetAllSystemSettingEntity(out List<SystemSettingEntity> systemSettingEntityList)
        {
            var target = DataContext.SystemSettings.ToList();
            systemSettingEntityList = new List<SystemSettingEntity>();
            foreach (var item in target)
            {
                systemSettingEntityList.Add(new SystemSettingEntity(item));
            }

            return true;
        }

        ///// <summary>
        ///// 获取单个
        ///// </summary>
        ///// <param name="rowId"></param>
        ///// <param name="systemSettingEntity"></param>
        ///// <returns></returns>
        //public bool GetSystemSettingEntityById(string rowId, out SystemSettingEntity systemSettingEntity)
        //{
        //    DAL.SystemSetting systemSetting = DataContext.SystemSettings.SingleOrDefault(obj => obj.RowID == rowId);
        //    systemSettingEntity = new SystemSettingEntity(systemSetting);

        //    return true;
        //}
        //
        ///// <summary>
        ///// 新增
        ///// </summary>
        ///// <param name="systemSetting"></param>
        ///// <returns></returns>
        //public bool Add(SystemSettingEntity systemSetting)
        //{
        //    SystemSetting sysset = new SystemSetting();
        //    if (systemSetting.ID == null || systemSetting.ID == String.Empty)
        //        sysset.RowID = System.Guid.NewGuid().ToString();
        //    else
        //        sysset.RowID = systemSetting.ID;
        //    sysset.ParamName = systemSetting.Name;
        //    sysset.ParamValue = systemSetting.ParamValue;
        //    sysset.ParamDesc = systemSetting.ParamValue;
        //    sysset.ModDate = System.DateTime.Now;

        //    DataContext.SystemSettings.InsertOnSubmit(sysset);
        //    DataContext.SubmitChanges();

        //    return _result;
        //}

        ///// <summary>
        ///// 更新
        ///// </summary>
        ///// <param name="systemSetting"></param>
        ///// <returns></returns>
        //public bool Update(SystemSettingEntity systemSetting)
        //{
        //    SystemSetting sysset = DataContext.SystemSettings.SingleOrDefault(obj => obj.RowID == systemSetting.ID);
        //    if (sysset == null)
        //        return false;

        //    sysset.ParamName = systemSetting.Name;
        //    sysset.ParamValue = systemSetting.ParamValue;
        //    sysset.ParamDesc = systemSetting.ParamValue;
        //    sysset.ModDate = System.DateTime.Now;

        //    DataContext.SubmitChanges();

        //    return _result;
        //}

        ///// <summary>
        ///// 删除
        ///// </summary>
        ///// <param name="ID"></param>
        ///// <returns></returns>
        //public bool DeleteSystemSettingEntity(string ID)
        //{
        //    SystemSetting sysset = DataContext.SystemSettings.SingleOrDefault(obj => obj.RowID == ID);
        //    if (sysset != null)
        //    {
        //        DataContext.SystemSettings.DeleteOnSubmit(sysset);
        //        DataContext.SubmitChanges();
        //    }

        //    return _result;
        //}
        #endregion
    }
}
